<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Role
 * @package App\Models
 * @version October 14, 2017, 11:55 am CST
 *
 * @property string name
 * @property string desc
 * @property integer status
 */
class Role extends Model
{
    use SoftDeletes;

    public $table = 'roles';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'name',
        'display_name',
        'desc',
        'status'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'name' => 'string',
        'desc' => 'string',
        'status' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        
    ];

    public function users()
    {
        return $this->belongsToMany('App\User');
    }

    public function abilities()
    {
        return $this->belongsToMany('App\Models\Ability');
    }

    public function ability($ability)
    {
        return $this->abilities->keyBy('name')->get($ability, false);
    }

    public function user_ids()
    {
        return $this->users()->pluck('user_id')->toArray();
    }
}
